package plugins.openform;

import com.alibaba.druid.util.StringUtils;
import com.mongodb.QueryBuilder;
import kd.bos.bill.BillShowParameter;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.ext.form.container.MessageCarouselContainer;
import kd.bos.form.ShowType;
import kd.bos.form.control.Control;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.permission.PermissionServiceHelper;
import kd.sdk.plugin.Plugin;

import java.util.*;
import java.util.List;

/**
 * 动态表单插件
 */
public class home_picture_jumpto extends AbstractFormPlugin {
    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        // 监听图片控件B的点击事件
        this.addClickListeners("dcb4_imageap");
    }

    @Override
    public void click(EventObject evt) {
        Control source = (Control) evt.getSource();
        if ("dcb4_imageap".equals(source.getKey())) {
            // 1. 查询单据C中编号H0001的单据ID
            QFilter filter = new QFilter("billno", QCP.equals, "H0001");
            DynamicObject[] bills = BusinessDataServiceHelper.load("dcb4_huodong", "id", new QFilter[]{filter});

            if (bills != null && bills.length > 0) {
                Object pkId = bills[0].get("id");

                // 2. 构建单据打开参数
                BillShowParameter showParam = new BillShowParameter();
                showParam.setFormId("dcb4_huodong");
                showParam.setPkId(pkId.toString());
                showParam.getOpenStyle().setShowType(ShowType.Modal); // 模态框打开

                // 3. 打开指定单据
                this.getView().showForm(showParam);
            } else {
                this.getView().showTipNotification("未找到编号H0001的单据");
            }
        }
    }

}

